package chapter18;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author lzy
 * @create 2018-05-04 上午9:12
 */
public class TestDemo {
    public static void main(String[] args) {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("application.xml");
        RedisTemplate template = ctx.getBean(RedisTemplate.class);
        // 设值
        template.opsForValue().set("key1", "value1");
        template.opsForValue().set("key2", "value2");
        // 通过key获取值
        String value1 = (String) template.opsForValue().get("key1");
        System.out.println(String.format("key1:%s", value1));
        // 通过key删除值
        template.delete("key1");
        // 求长度
        long len = template.opsForValue().size("key2");
        System.out.println(String.format("value2_len:%d", len));
    }
}